package com.project.dao.Impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class BaseDao {
    /**
     * 连接对象
     */
    protected Connection con;
    /**
     * Sql语句执行对象
     */
    protected PreparedStatement ps;
    /**
     * 结果集
     */
    protected ResultSet rs;

    public void setConnection() {
        try {
//            com.mysql.jdbc.Driver
            Class.forName("com.mysql.jdbc.Driver");
            this.con = DriverManager.getConnection("jdbc:mysql://localhost:12345/mydb?characterEncoding=utf-8", "root", "lovo");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void closeConnection() {
        try {
            if (rs != null) {
                rs.close();
            }
            if (ps != null) {
                ps.close();
            }
            if (con != null) {
                con.close();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
